package com.sylingd.blog.lib

import android.preference.PreferenceManager
import com.sylingd.blog.BaseApplication

object Setting {

	private val handler = PreferenceManager.getDefaultSharedPreferences(BaseApplication.instance)

	const val NAME_CONTENT_TEXT_SIZE = "content_text_size"
	const val DEFAULT_CONTENT_TEXT_SIZE = "16"

	fun get(key: String, defaultVal: String = ""): String {
		return handler.getString(key, defaultVal)
	}
	fun get(key: String, defaultVal: Int): Int {
		return handler.getInt(key, defaultVal)
	}
	fun get(key: String, defaultVal: Boolean): Boolean {
		return handler.getBoolean(key, defaultVal)
	}

	fun set(key: String, value: Any) {
		val editor = handler.edit()
		when {
			value is Int -> editor.putInt(key, value)
			value is String -> editor.putString(key, value)
			value is Boolean -> editor.putBoolean(key, value)
		}
		editor.apply()
	}
}